home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug233 / pop.c < prev    next >
Text File  |  1987-06-30  |  1KB  |  27 lines

  1. /* pop.c -- changes to last directory stored in file cdstack.dat (LIFO) */
  2.  
  3. #include <string.h>
  4. #include <direct.h>
  5. #include <stdio.h>
  6.  
  7. main()
  8. {
  9.    FILE *fi;
  10.    char c[67];
  11.    int result;
  12.    long length, pos;
  13.  
  14.    pos = -(sizeof(c));   /*set to size of 67 chars */
  15.    fi = fopen("c:\\cdstack.dat", "r+"); /*open for reading and writing */
  16.       /* position filepointer 67 chars from end of file  */
  17.    result = fseek(fi,pos,SEEK_END);
  18.    fscanf(fi,"%s",c);   /* read the stored path innto "c" */
  19.    chdir(c);            /* change to last directory stored with PUSH */
  20.    length = filelength(fileno(fi)); /* get size of file in bytes */
  21.         /* truncate file by cutting 67 bytes from end */
  22.    result = chsize(fileno(fi), (length - (sizeof(c))));
  23.    length = filelength(fileno(fi));  /*get new length of cdstack.dat */
  24.    fclose (fi);
  25.    if (length < 67)    /* if  cdstack.dat is now less than 67 bytes */
  26.       result = remove("c:\\cdstack.dat");     /* erase it*/
  27. }